/**
 * Created by huyoufu on 2021/7/6 18:09.
 * contact me -->https://www.jk1123.com
 */

#include <gtest/gtest.h>
#include "ds/list.h"
#include <sys/time.h>

struct my_task {
    char *name;
    hllist l;
};
TEST(list_test,mm){

    for (int k = 0; k <10000 ; ++k) {
        int n=100000;
        char* ss[n];
        for (int i = 0; i < n; ++i) {
            char *buff = (char *) (malloc(6 + 10));
            sprintf(buff, "%s%d", "任务", i);
            ss[i]=buff;
        }

        for (int j = 0; j < n; ++j) {
            free(ss[j]);
        }
        printf("结束了一次:%d\n",k);

    }
    printf("结束了~~~~~~\n");

}

TEST(list_test, list_for_each) {
    LIST_HEAD(x);
    //创建一个新的节点
    for (int i = 0; i < 10000 * 10000; ++i) {
        //创建十个任务
        struct my_task *task = (my_task *) (malloc(sizeof(struct my_task)));
        char *buff = (char *) (malloc(6 + 10));
        sprintf(buff, "%s%d", "任务", i);
        task->name = buff;

        head_link_list_tail(&x, &(task->l));

    }
    struct head_link_list *head = &x;
    //遍历了

    hllist *node;
    hllist *tmp;
    /*list_for_each(tmp,head){
        struct my_task *task = container_of(tmp, struct my_task, l);
        printf("任务是:%s\n", task->name);
    }*/
    list_for_each_safe(node, tmp, head) {
        struct my_task *task = container_of(node, struct my_task, l);
        //删除该元素
        list_del(node);
        free(task->name);
        free(task);
    }

    ASSERT_EQ(1, 2);
}
